using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LitTools
{
    public class BTNode_Composite_Sequence : BTNode_Composite
    {
        private int childIndex;

        public BTNode_Composite_Sequence(string name)
        {
            this.name = name;
        }

        protected override void OnStart()
        {
            childIndex = 0;
        }

        protected override void OnStop()
        {

        }

        protected override BTNodeState OnUpdate()
        {
            var child = children[childIndex];
            switch (child.Update())
            {
                case BTNodeState.Running:
                    return BTNodeState.Running;
                case BTNodeState.Failure:
                    return BTNodeState.Failure;
                case BTNodeState.Success:
                    childIndex++;
                    break;
                default:
                    break;
            }
            return childIndex == children.Count ? BTNodeState.Success : BTNodeState.Running;
        }
    }
}